<template>
  <div class="prompt-container" v-if="isVisible">
    <div class="prompt-box">
      <div class="prompt-title">
        <div style="display: flex; align-items: center">
          <svg-icon
            icon-class="cuowu_icon"
            style="width: 16px; height: 16px; margin-right: 8px"
          />
          <div>错误提示</div>
        </div>
        <el-icon color="#fff" @click="cancelPrompt" size="16"><Close /></el-icon>
      </div>
      <div class="prompt-content">
        <div class="prompt-content-box">
          <svg-icon
            icon-class="cuowu_icon"
            style="flex:0 0 16px; height: 16px; margin-right: 8px;color:#EB4015"
          />
        <el-popover
            placement="top-start"
            title=""
            :width="400"
            trigger="hover"
            :content="title"
        >
            <template #reference>
                <div class="prompt-content-box-content">
                    {{ title }}
                </div>
            </template>
        </el-popover>
        </div>
      </div>
      <div class="detail-info">
        <div class="detail-info-top" @click="infoClick">
            <div class="detail-info-top-title">详细信息</div>
            <svg-icon
                v-if="!infoVisible"
                icon-class="xiangxia"
                style="flex:0 0 16px; height: 16px; margin-left: 4px;"
            />
            <svg-icon
                v-else
                icon-class="xiangshang"
                style="flex:0 0 16px; height: 16px; margin-left: 4px;"
            />
        </div>
        <div class="detail-info-content">
          <el-collapse-transition>
            <div v-show="infoVisible" v-html="infos"></div>
          </el-collapse-transition>
        </div>
      </div>
      <div class="prompt-footer">
        <el-button type="primary" @click="cancelPrompt">确定</el-button>
      </div>
    </div>
  </div>
</template>

<script setup>
import { ref } from "vue";
const { proxy } = getCurrentInstance();
const isVisible = ref(false);
const title = ref('')
const infos = ref('')
const infoVisible = ref(false)
const showPrompt = (newTitle,info) => {
  title.value = newTitle
  console.log(decodeEscapeSequence(info));
  infos.value = decodeEscapeSequence(info)
  isVisible.value = true;
};

const cancelPrompt = () => {
  isVisible.value = false;
};

function infoClick() {
  infoVisible.value = !infoVisible.value
}

function decodeEscapeSequence(str) {
  return str.replace(/\r\n/g, '<br>');
}

defineExpose({
  isVisible,
  showPrompt,
  cancelPrompt,
});
</script>

<style lang="scss" scoped>
.prompt-container {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.5);
  border-radius: 4px 4px 4px 4px;
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 10000;
}

.prompt-box {
  background-color: #fff;
  width: 612px;
  border-radius: 2px;
  box-shadow: 0px 12px 32px 4px rgba(0, 0, 0, 0.04),
    0px 8px 20px rgba(0, 0, 0, 0.08);
  .prompt-title {
    font-size: 18px;
    color: #303133;
    width: 100%;
    height: 40px;
    padding: 0 16px;
    box-sizing: border-box;
    background: #697786;
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 14px;
    color: #ffffff;
  }
  .prompt-content {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px 0;
    box-sizing: border-box;
    .prompt-content-box{
        width: 564px;
        height: 48px;
        background: #F5E9E6;
        border-radius: 4px 4px 4px 4px;
        border: 1px solid #EB4015;
        display: flex;
        align-items: center;
        padding: 14px 6px 14px 20px;
        box-sizing: border-box;

        .prompt-content-box-content{
            flex: 1;
            font-size: var(--size);
            color: #333333;
            overflow: hidden;
            text-overflow: ellipsis;
            white-space: nowrap;
            cursor: pointer;
        }
    }
  }
  .detail-info{
    padding: 0 24px 24px 24px;
    box-sizing: border-box;
    .detail-info-top{
        display: flex;
        align-items: flex-end;
        color: #333333;
        .detail-info-top-title{
            font-size: var(--size);
        }
    }
    .detail-info-content{
        font-size: var(--size);
        color: #999999;
        width: 100%;
        margin-top: 16px;
        max-height: 188px;
        overflow-y: auto;
    }
  }
}

button {
  padding: 8px 15px;
  margin: 5px;
  cursor: pointer;
}
.prompt-footer {
  width: 100%;
  height: 68px;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  border-top: 1px solid #E0E0E0;
  padding-right: 16px;
  box-sizing: border-box;
}
</style>
<style>
.el-popper{
    z-index: 100000 !important;
}
</style>